//
//  AppDelegate.m
//  JHHQB
//
//  Created by jinrongweidian on 17/3/21.
//  Copyright © 2017年 我爱微点. All rights reserved.
//

#import "AppDelegate.h"

#import "RDVTabBarController.h"
#import "RDVTabBarItem.h"
#import "QJMainHomeViewController.h"
#import "QJMyInfoViewController.h"

@interface AppDelegate ()

@property (nonatomic, strong) UIViewController *baseViewController;

@end

@implementation AppDelegate

#pragma mark - APP Launch Method
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    [self showHomeTabBarViewController];
    [self customizeInterface];
    
    return YES;
}










#pragma mark - Configure Main Page Methods
//设置tabBarController 里面放入四个导航器
- (void)setupViewControllers {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
    QJMainHomeViewController *home = [[QJMainHomeViewController alloc] init];
    UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:home];
    
    QJMyInfoViewController *my = [[QJMyInfoViewController alloc] init];
    UINavigationController *nav4 = [[UINavigationController alloc] initWithRootViewController:my];
    RDVTabBarController *tabBarController = [[RDVTabBarController alloc] init];
    
    [tabBarController setViewControllers:@[
                                           nav1,
                                           nav4
                                           ]];
    
    RDVTabBar *tabBar = [tabBarController tabBar];
    [tabBar setHeight:57.0f];
    tabBar.translucent = YES;
    
    self.baseViewController = tabBarController;
    [self customizeTabBarForController:tabBarController];
    
}

- (void)customizeTabBarForController:(RDVTabBarController *)tabBarController {

    NSArray *tabBarItemImages = @[ @"tab1_bar", @"tab5_bar"];
    NSArray *tabBarItemTitles = @[@"首页", @"我的"];
    
    for (RDVTabBarItem *item in [[tabBarController tabBar] items]) {

        NSInteger index = [[[tabBarController tabBar] items] indexOfObject:item];
        
        UIImage *selectedimage = [UIImage
                                  imageNamed:[NSString stringWithFormat:@"%@_selected",
                                              [tabBarItemImages
                                               objectAtIndex:index]]];
        UIImage *unselectedimage = [UIImage
                                    imageNamed:[NSString stringWithFormat:@"%@_normal",
                                                [tabBarItemImages
                                                 objectAtIndex:index]]];
        [item setFinishedSelectedImage:selectedimage
           withFinishedUnselectedImage:unselectedimage];
        [item setTitle:[tabBarItemTitles objectAtIndex:index]];
        
        //设置标签栏标题的选中颜色和未选中时的颜色
        NSDictionary *unSeletedTittleAttributes = nil;
        unSeletedTittleAttributes = @{
                                      NSFontAttributeName : [UIFont boldSystemFontOfSize:12],
                                      NSForegroundColorAttributeName : [UIColor darkGrayColor],
                                      };
        
        [item setUnselectedTitleAttributes:unSeletedTittleAttributes];
        
        NSDictionary *seletedTittleAttributes = nil;
        
        seletedTittleAttributes = @{
                                    NSFontAttributeName : [UIFont boldSystemFontOfSize:12],
                                    NSForegroundColorAttributeName : TABBAR_TEXT_COLOR
                                    };
        
        [item setSelectedTitleAttributes:seletedTittleAttributes];
        
        index++;
    }
}


- (void)showHomeTabBarViewController {
    [self setupViewControllers];
    self.window.rootViewController = self.baseViewController;
    [self.window makeKeyAndVisible];
}


#pragma mark - NavigationBar Appearance
//设置导航器的通用背景显示（背景颜色、文本大小、字体、颜色）
- (void)customizeInterface {

    UINavigationBar *navigationBarAppearance = [UINavigationBar appearance];
    UIImage *backgroundImage = nil;
    NSDictionary *textAttributes = nil;
    
    backgroundImage = [ImageHelper imageWithColor:NAVIBAR_BACK_COLOR];
    
    textAttributes = @{
                       NSFontAttributeName : [UIFont systemFontOfSize:18],
                       NSForegroundColorAttributeName : NAVIBAR_TEXT_COLOR,
                       };
    
    [navigationBarAppearance setBackgroundImage:backgroundImage
                                  forBarMetrics:UIBarMetricsDefault];
    [navigationBarAppearance setTitleTextAttributes:textAttributes];
    [navigationBarAppearance setTintColor:NAVIBAR_TINT_COLOR];
    
}





#pragma mark - APP Life Methods
- (void)applicationWillResignActive:(UIApplication *)application {
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
}


- (void)applicationWillTerminate:(UIApplication *)application {
}


@end
